<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <h2>Vue 简单的留言板</h2>
        <h3>显示留言</h3>
        <div v-for="(v,i) in list" v-bind:key="i">
            <h5>序号：{{i+1}}</h5>
            <p>内容：{{v.title}}</p>
            <p>
                <button v-on:click="list.splice(v,1)">删除</button>
                <button v-on:click="updateOne(v,i)">修改</button>
            </p>
        </div>

        <hr>
        <div>
            <h2>发布留言</h2>
            <p>
                <input type="text" placeholder="请输入..." v-model="word">
            </p>
            <p>
                <button v-on:click="addToList">发送</button>
            </p>
        </div>
    </div>





    <script>
        const vm = new Vue({
            el: "#app",
            data: {
                word: '',
                list: [
                    {
                        title: "6161"
                    },
                    {
                        title: "端午端午"
                    }
                ]
            },
            methods: {
                //修改内容
                updateOne(v, i) {
                    let value = window.prompt(i, v.title);
                    console.log(value);
                    if (value && value != v.title) {
                        v.title = value;
                        this.list.splice(i, 1, v);
                    }
                },

                //添加
                addToList() {
                    console.log(6666);
                    this.list.push({
                        title: this.word
                    })
                    this.word = ''

                }
            }
        })



    </script>

</html>